<?php

use yii\db\Migration;

class m171211_033332_create_full_activities extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }

    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%full_activities}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'name' => $this->string(100)->defaultValue(null)->comment('满增名称'),
                'type' => $this->smallInteger(1)->defaultValue(0)->comment('三大类（1 益智  2 音乐  3  形体）'),
                'money' => $this->decimal(10,2)->defaultValue(0)->comment('满金额'),
                'give_money' => $this->decimal(10,2)->defaultValue(0)->comment('赠送金额'),
                'start_time' => $this->integer()->defaultValue(0)->comment('开始时间'),
                'end_time' => $this->integer()->defaultValue(0)->comment('结束时间'),
                'number' => $this->smallInteger()->defaultValue(0)->comment('活动人数'),
                'status' => $this->smallInteger()->defaultValue(1)->comment('状态 1 启用 2 禁用'),
                'created_at' => $this->integer()->defaultValue(0)->comment('创建时间'),
            ]);
            $this->addCommentOnTable('{{%full_activities}}','满额赠送金额表');
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%full_activities}}');
        }
    }
}
